﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Entites
{
   public class ApplicationDbContext : DbContext
    {

        public ApplicationDbContext(DbContextOptions options ):base(options)
        { 
          
        
        }
        public DbSet<User> User { get; set; }
        public DbSet<Role> Role { get; set; }

        public DbSet<ActionPermission> ActionPermission { get; set; }
        public DbSet<Menu> Menu { get; set; }

        public DbSet<UserRole> UserRole { get; set; }
        public DbSet<FrontIcon> FrontIcon { get; set; }
        public DbSet<MenuPermission> MenuPermission { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            if (modelBuilder != null)
            {
                modelBuilder.Entity<UserRole>().HasKey(t => new { t.RoleId, t.UserId });
                modelBuilder.Entity<UserRole>().HasOne(p => p.User).WithMany(pt => pt.UserRoles).HasForeignKey(o => o.UserId);
                modelBuilder.Entity<UserRole>().HasOne(p => p.Role).WithMany(pt => pt.UserRoles).HasForeignKey(o => o.RoleId);

            }

                }






    }
}
